package com.liu.manager.controller;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONWriter;
import com.liu.manager.bean.ResponseResult;
import com.liu.manager.entity.SysRoler;
import com.liu.manager.service.SysrolerService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "/sysroler")
public class SysrolerController {

    @Resource
    SysrolerService sysrolerService;

    @PostMapping(value = "/addRoler",produces = {"application/json;charset=utf-8"})
    public String addRoler(@RequestBody SysRoler sysRoler){
        ResponseResult responseResult = sysrolerService.insertRoler(sysRoler);
        return JSON.toJSONString(responseResult, JSONWriter.Feature.FieldBased,JSONWriter.Feature.WriteNulls);
    }

    @PostMapping(value = "/removeRoler",produces = {"application/json;charset=utf-8"})
    public String removeRoler(long id){
        ResponseResult responseResult = sysrolerService.deleteRoler(id);
        return JSON.toJSONString(responseResult, JSONWriter.Feature.FieldBased,JSONWriter.Feature.WriteNulls);
    }

    @GetMapping(value = "/findById",produces = {"application/json;charset=utf-8"})
    public String findById(long id){
        ResponseResult responseResult = sysrolerService.findSysRolerById(id);
        return JSON.toJSONString(responseResult, JSONWriter.Feature.FieldBased,JSONWriter.Feature.WriteNulls);
    }

    @GetMapping(value = "/findAll",produces = {"application/json;charset=utf-8"})
    public String findAll(){
        ResponseResult responseResult = sysrolerService.getAllrolers();
        return JSON.toJSONString(responseResult, JSONWriter.Feature.FieldBased,JSONWriter.Feature.WriteNulls);
    }
}
